package com.dcbeida.activity.salsesdedail;


import android.app.Activity;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.util.Log;

import com.dcbeida.MyApplication;
import com.dcbeida.bean.User;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.model.ModelUtils;
import com.dcbeida.utils.JsonGet;

import java.lang.reflect.Type;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by hp on 2016/5/12.
 */
public class SalsesDetailUpdatePresenter implements SalsesDetailUpdateContract.Present {


    private SalsesDetailUpdateContract.View view;

    private ModelUtils model;

    private Activity act;

    public SalsesDetailUpdatePresenter(SalsesDetailUpdateContract.View view, Activity act) {
        //我这里直接把activity作为view，所以不需要
        //mView.setPresenter(this);
        this.view = view;
        model = ModelUtils.newInstance();
        this.act = act;

    }


    @Override
    public void start() {

    }


    //取消dialog 取消请求
    DialogInterface.OnCancelListener lis = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            model.getCancel();
        }
    };

    @Override
    public void sbumit(String orderid, String hospitalid, String doctorid, String doctorname, String amount,
                       String hasrelate, String invoiceimgurl,String recipepicsurl, String receiptimgurl,String trueName,String phone) {
        model.getDate("updateorder", new JsonGet().putopt("orderid", orderid)
                .putopt("hospitalid",hospitalid)
                .putopt("doctorid", doctorid)
                .putopt("doctorname", doctorname)
                .putopt("amount", amount)
                .putopt("hasrelate", hasrelate)
                .putopt("patienttruename", trueName)
                .putopt("patientphonenum", phone)
                .putopt("invoiceimgurl", invoiceimgurl)
                .putopt("receiptimgurl", receiptimgurl)
                .putopt("recipepicsurl", recipepicsurl)
                .putopt("uid", MyApplication.user.getUid())
                .putopt("shopid", MyApplication.user.getShopid())
                .tostring(), new bindCallBack(act, User.class, lis));
    }


    final class bindCallBack<T> extends DialogCallback<T> {

        public bindCallBack(Activity activity, Type type, DialogInterface.OnCancelListener listener) {
            super(activity, type, listener);
        }

        @Override
        public void onResponse(T data) {
            if (data != null) {
                //绑定成功失败返回
                view.showTip("修改成功");
            }

        }


        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            //view.showTip("网络异常，请重试");
            Log.i("sean", "+++++++绑定Umeng账号失败");
        }
    }


}
